package com.arraylist;

import java.util.ArrayList;
import java.util.Iterator;

public class StudentTest {
    public static void main(String[] args) {
        ArrayList<Student> arrayList = new ArrayList<>();
        arrayList.add(new Student(20,"zhangsan",80 ,"18"));
        arrayList.add(new Student(20,"wangwu",60 ,"19"));
        arrayList.add(new Student(19,"lisi",60 ,"19"));
        Integer resultAge = 0;
        ArrayList<String> tempList = new ArrayList<>();
        Iterator<Student> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Student next = iterator.next();
            if (!(tempList.contains(next.getClassNum()))) {
                tempList.add(next.getClassNum());
            }
        }
        System.out.println(tempList);

        for (int i = 0; i < tempList.size(); i++) {
            int classScore = 0;
            int classNum = 0;
            for (int j = 0; j < arrayList.size(); j++) {
                if (tempList.get(i).equals(arrayList.get(j).getClassNum())) {
                    classScore = classScore + arrayList.get(i).getScore();
                    classNum++;
                }
            }
            System.out.println(classScore/ classNum);
        }
        }


    }

